﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EventReminder.Client
{
    internal partial class RegisterDialog : Form
    {
        EventReminderController _controller;
        public RegisterDialog()
            : this(null)
        { }

        internal RegisterDialog(EventReminderController controller)
        {
            _controller = controller;
            _controller.LoginSucceeded += new EventHandler(HandleLoginSucceeded);

            InitializeComponent();
        }

        private void HandleBtnSubmit_Click(object sender, EventArgs e)
        {
            _controller.AttemptRegister(txtUsername.Text,
                txtPassword.Text,
                txtPassword2.Text,
                txtFirstName.Text,
                txtLastName.Text,
                txtEmail.Text);
        }

        private void btnQuit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void RegisterDialog_Shown(object sender, EventArgs e)
        {
            txtUsername.Focus();
        }

        void HandleLoginSucceeded(object sender, EventArgs e)
        {
            if (this.Visible)
            {
                this.Close();
            }
        }

        protected override void OnClosed(EventArgs e)
        {
            _controller.LoginSucceeded -= new EventHandler(HandleLoginSucceeded);
            base.OnClosed(e);
        }
    }
}
